package com.gzedu.fun.demo.logic.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.gzedu.R;
import com.gzedu.frame.logic.adapter.McBaseAdapter;

public class DemoAdapter extends McBaseAdapter implements OnTouchListener{
	
	private Map<String,String> map;

	private  List<Map<String, String>> list;
	
	public DemoAdapter(Context _context, List<Map<String, String>> _list) {
		super(_context, _list);
		this.list=_list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = layoutInflater.inflate(
					R.layout.demo_item, null);
			viewHolder = new ViewHolder();
			viewHolder.contactGroupName = (TextView) convertView
					.findViewById(R.id.demo_item_contactGroupName);
			convertView.setTag(viewKey, viewHolder);
			convertView.setOnTouchListener(this);
		} else {
			viewHolder = (ViewHolder) convertView.getTag(viewKey);
		}
		map=list.get(position);
		if(map!=null&&map.size()>0){
			viewHolder.contactGroupName.setText(map.get("CONTACTGROUPNAME"));
		}
		return convertView;
	}

	private static class ViewHolder {
		TextView contactGroupName;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		int action=event.getAction();
		float startX=0;
		float endX=0;
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			startX=event.getX();
			break;
		case MotionEvent.ACTION_UP:
			endX=event.getX();
			break;
		default:
			break;
		}
		if(Math.abs(startX-endX)>150){
			ImageView imageView=(ImageView) v.findViewById(R.id.demo_item_ImageView);
			Button button=(Button) v.findViewById(R.id.demo_item_Button);
			Animation animation=AnimationUtils.loadAnimation(context, R.anim.in_from_left);
			imageView.setAnimation(animation);
			imageView.setVisibility(View.VISIBLE);
			button.setVisibility(View.VISIBLE);
		}
		return false;
	}

}
